package com.zyw.conf;

import org.crazycake.shiro.RedisCacheManager;
import org.crazycake.shiro.RedisManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedisCacheConfig {
	@Value("${spring.redis.host}")
	private String redisHost;
	
	@Value("${spring.redis.password}")
	private String redisPassword;
	
	@Value("${spring.redis.port}")
	private int redisPort; 
	
	@Value("${spring.redis.timeout}")
	private int redisTimeout;
	
	@Value("${spring.redis.expire}")
	private int redisExpire;
	
	/**
	 * <p>cacheManager缓存 redis实现</p>
	 */
	@Bean(name = "redisCacheManager")
	public RedisCacheManager cacheManager() {
		RedisManager redisManager = new RedisManager();
		redisManager.setHost(this.redisHost);
		redisManager.setPassword(this.redisPassword);
		redisManager.setPort(this.redisPort);
		redisManager.setTimeout(this.redisTimeout);
		redisManager.setExpire(this.redisExpire);
		RedisCacheManager redisCacheManager = new RedisCacheManager();
		redisCacheManager.setRedisManager(redisManager);
		return redisCacheManager;
	}
	
}
